<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        a {
            text-decoration: none;
            color: #000;
        }
        
        #box {
            width: 400px;
            background: pink;
            padding: 20px 50px;
            border-radius: 10px;
            transform: translate(-50%, -50%);
            position: fixed;
            top: 50%;
            left: 50%;
        }
        
        #box1 {
            text-align: center;
        }
        
        #denglu,
        #zhuc {
            font-size: 24px;
            margin-right: 20px;
        }
        
        #zhuc {
            border: 1px solid red;
            display: inline-block;
            margin-bottom: 20px;
        }
        
        p {
            margin-top: 10px;
        }
        
        #warp {
            margin-left: 102px;
            width: 200px;
            height: 30px;
            border-radius: 5px;
            margin-top: 30px;
            background: peru;
        }
    </style>
</head>

<body>
    <div id="box">
        <div id="box1">
            <span id="denglu">登录</span>
            <span id="zhuc"><a href="./zhu.html">注册</a></span>
        </div>
        <p>用户名：<input type="text" id="username"></p>
        <p>密 码：<input type="password" id="list"></p>
        <!-- <p><input type="checkbox" id="ck">30天免登录</p> -->
        <button id="warp">登录</button>

    </div>
    <script src="jquery.min.js"></script>
    <script>
        $("#warp").click(function() {
            $.ajax({
                url: "http://10.35.170.123:81/haha",
                data: {
                    username: $("#username").val(),
                    pwd: $("#list").val()
                },
                success(data) {
                    console.log(data);
                    var data = JSON.parse(data)
                    console.log(data);

                    if (data.length !== 0) {
                        if ($("#list").val() === data[0].password) {
                            sessionStorage.setItem("name", $("#username").val())
                            if ($("#ck")[0].checked) {
                                let date = new Date();
                                date.setDate(date.getDate() + 30);
                                document.cookie = `${name}=${$("#username").val()};expires=${date}`
                            }
                            // location.href = "student.html"

                        } else {
                            alert("密码输入错误，请重新输入")
                        }
                    } else {
                        alert("请您先去注册")
                        location.href = "zhu.html"
                    }
                }
            })
        })
    </script>
</body>

</html>